
#include <windows.h>

HANDLE hMutex1;
HANDLE hMutex2;

DWORD WINAPI Thread1(LPVOID dummy)
{
	WaitForSingleObject(hMutex1, INFINITE);
	Sleep(1000);
	WaitForSingleObject(hMutex2, INFINITE);
	return 0;
}

DWORD WINAPI Thread2(LPVOID dummy)
{
	WaitForSingleObject(hMutex2, INFINITE);
	Sleep(1000);
	WaitForSingleObject(hMutex1, INFINITE);
	return 0;
}

int main()
{
	HANDLE threads[2];

	hMutex1 = CreateMutex(NULL, FALSE, L"FirstMutex");
	hMutex2 = CreateMutex(NULL, FALSE, L"SecondMutex");

	threads[0] = CreateThread(NULL, 0, Thread1, NULL, 0, NULL);
	threads[1] = CreateThread(NULL, 0, Thread2, NULL, 0, NULL);
	WaitForMultipleObjects(ARRAYSIZE(threads), threads, TRUE, INFINITE);

	return 0;
}